<script setup>
import { inject, ref } from "vue";
// import stepsview from "../components/steps/steps.vue";
import { useCounterStore } from "@/stores/upgrade";
import { handleGoBack } from "@/utils/router";
import { upgradecreate, upgradeagreeInfo } from "@/services/upfrade";
import { uploadfile } from "@/services/upload";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { base_URL } from "@/utils/http";
import { refunddetail, refundcancel } from "@/services/order";
import { object } from "uview-plus/libs/function/test";

onLoad((e) => {
  if (e.refund_id) {
    getdet(e.refund_id);
  }
});
const detobj = ref({});

async function getdet(id) {
  let res = await refunddetail({ refund_id: id });
  detobj.value = res.data;
}

const jcfun = (id) => {
  uni.navigateTo({
    url: "/pages/order/returndet/index?refund_id=" + id,
  });
};

const refund_id = ref(0);
const showOrder = ref(false);

const canlfun = (id) => {
  showOrder.value = true;
  refund_id.value = id;
};

const closeOrder = () => {
  showOrder.value = false;
};
const orderSubmit = async () => {
  try {
    let res = await refundcancel({ refund_id: refund_id.value });
    if (res.code == 200) {
      uni.showToast({
        title: "撤销成功",
        icon: "none",
      });
      showOrder.value = false;
      setTimeout(() => {
        uni.redirectTo({
          url: "/pages/order/orderlist/index?status=4",
        });
      }, 1000);
    }
  } catch (e) {
    uni.showToast({
      title: e.info,
      icon: "none",
    });
    showOrder.value = false;
  }
};
</script>

<template>
  <view class="content">
    <view class="header-list">
      <view class="header-list-title">
        <view class="header-list-title-arr">
          <!-- <view v-if="objdet.paid == 0">{{ objdet.paid_text }}</view> -->
          <view>{{ detobj.status_text }}</view>
          <text v-if="detobj.refund_type && detobj.refund_type == 2"
            >退款退货</text
          >
          <text v-if="detobj.refund_type && detobj.refund_type == 1"
            >仅退款</text
          >
        </view>
        <image src="@/pages/order/static/icon1.png" mode="scaleToFill" />
      </view>
    </view>
    <view class="content-let-top">
      <view class="content-top" v-if="detobj.status == 1">
        <view class="content-top-title">售后申请已提交</view>
        <view class="content-top-dec">请在<text>两天内</text>提交快递单号</view>
      </view>
      <view class="list">
        <view class="list-item">
          <!-- <view class="list-item-title">
          <text>订单编号：49832483231</text>
          <text class="list-item-title">待支付</text>
        </view> -->
          <view class="list-item-content">
            <view
              class="list-item-content-item"
              v-for="(item, index) in detobj.refundProduct"
              :key="index"
            >
              <view class="list-item-content-img">
                <image
                  :src="
                    item.order_product_info ? item.order_product_info.image : ''
                  "
                  mode=""
                ></image>
              </view>
              <view class="list-item-content-info">
                <view class="list-item-content-info-title">
                  <view class="good-name">
                    <text>{{
                      item.order_product_info
                        ? item.order_product_info.store_name
                        : ""
                    }}</text>
                  </view>
                  <view>
                    <text class="good-name-mr">默认</text>
                  </view>
                </view>
                <view class="list-item-price">
                  <view
                    >¥{{
                      item.order_product_info
                        ? item.order_product_info.price
                        : 1
                    }}</view
                  >
                  <view class="good-name-num"
                    >x{{ item.refund_num ? item.refund_num : 0 }}</view
                  >
                  <view
                    ><text class="good-name-text-index">{{
                      detobj.status_text
                    }}</text>
                  </view>

                  <!-- status_text -->
                </view>
                <view
                  v-if="detobj.status == 1"
                  class="list-item-btn-item-left-btn"
                  @click="jcfun(detobj.refund_id)"
                  >寄快递</view
                >
              </view>
            </view>
          </view>

          <!-- <view class="list-nums">
          <text>共1件, </text>
          <text>总计：</text><text class="list-nums-s">¥2000</text>
        </view>
        <view class="list-item-btn">
          <view class="list-item-btn-item-left">取消订单</view>
          <view class="list-item-btn-item-right">立即支付</view>
        </view> -->
        </view>
      </view>
    </view>
  </view>

  <u--form>
    <view class="user-form">
      <!-- required="true" -->
      <u-form-item label="订单编号" prop="name" borderBottom ref="item1">
        <view class="select"
          >{{ detobj.order_id }}
          <up-copy :content="detobj.order_id" @click.stop
            ><image
              src="@/pages/cloudlibrary/static/copy-img.png"
              mode="widthFix" /></up-copy
        ></view>
      </u-form-item>
      <u-form-item label="售后编号" prop="name" borderBottom ref="item1">
        <view class="select"
          >{{ detobj.refund_id
          }}<up-copy :content="detobj.refund_id" @click.stop
            ><image
              src="@/pages/cloudlibrary/static/copy-img.png"
              mode="widthFix" /></up-copy
        ></view>
      </u-form-item>
      <u-form-item label="退款原因" prop="name" borderBottom ref="item1">
        <view class="select">{{ detobj.refund_message }}</view>
      </u-form-item>
      <u-form-item label="退款金额" prop="phone" borderBottom ref="item1">
        <view class="select">¥{{ detobj.refund_price }}</view>
      </u-form-item>

      <view :class="detobj.status == -1 ? '' : 'item-line'">
        <u-form-item
          label="备注"
          labelWidth="150"
          prop="card_no"
          borderBottom
          ref="item1"
        >
          <view class="select">{{ detobj.mark ? detobj.mark : "---" }}</view>
        </u-form-item>
      </view>

      <view :class="detobj.status == -1 ? '' : 'item-line'">
        <u-form-item
          label="审核未通过"
          prop="card_no"
          borderBottom
          ref="item1"
          v-if="detobj.status == -1"
          labelWidth="150"
        >
          <view class="select">{{
            detobj.fail_message ? detobj.fail_message : "---"
          }}</view>
        </u-form-item>
      </view>
    </view>
    <!-- 
    <view class="uplade-up">
      <view class="uplade-up-title">上传凭证（3/6）</view>
     
      <up-upload
        :fileList="fileList4"
        @afterRead="
          (val) => {
            afterRead4(val, 4);
          }
        "
        @delete="
          (val) => {
            deletePic4(val, 4);
          }
        "
        name="1"
        multiple
        :maxCount="6"
      ></up-upload>
    </view> -->
  </u--form>

  <view class="content-footer" v-if="detobj.status == 0 || detobj.status == 1">
    <view class="contebt-pays">
      <!-- <view>
        <text>共1件</text>
        <text class="pay-hj">合计:</text>
        <text class="pay-bq">¥</text>
        <text class="pay-num">{{ num }}</text>
      </view> -->
      <!-- <up-button class="pay-bt-xs" text="支付"></up-button> -->
      <view @click="canlfun(detobj.refund_id)" class="pay-bt">撤销申请</view>
      <view
        v-if="detobj.status == 1"
        @click="jcfun(detobj.refund_id)"
        class="pay-bt pay-df"
        >寄快递</view
      >
      <!-- <view
        v-if="detobj.status == 1"
        class="list-item-btn-item-left-btn"
        @click="jcfun(detobj.refund_id)"
        >寄快递</view
      > -->
    </view>
  </view>
  <up-picker
    :show="show"
    @cancel="closefun"
    @close="closefun"
    :columns="columns"
    @confirm="confirmfun"
  ></up-picker>

  <!-- 撤销申请弹框 -->
  <view class="password_show">
    <u-popup
      :show="showOrder"
      mode="center"
      round="10"
      @close="close"
      @open="open"
    >
      <view class="productGift">
        <view class="popup-content-title">温馨提示</view>
        <view class="popup-content-item"
          >撤销申请无法回退，请确认撤销申请？</view
        >
        <view class="popup-content-box">
          <view class="popup-content-bt">
            <view class="popup-content-qx" @click="closeOrder">取消</view>
            <view class="popup-content-cl" @click="orderSubmit">确定</view>
          </view>
        </view>
      </view>
    </u-popup>
  </view>
</template>

<style lang="scss" scoped>
@import "./index.scss";
</style>
